home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: timing in C
- Date: 22 Mar 1996 14:34:11 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4iv9t3INNbbk@keats.ugrad.cs.ubc.ca>
- References: <Pine.SOL.3.91.960322090413.3536A-100000@exp3.wam.umd.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <Pine.SOL.3.91.960322090413.3536A-100000@exp3.wam.umd.edu>,
- charles r marks <chuckmx@wam.umd.edu> wrote:
- >How does one program timing into a C program? For example, I want to send
- >an output signal every millisecond for a minute and then change to every
- >other millisecond.
-
- The C standard does not define a real-time clock or timer facilities. The best
- you can do is call clock() and loop around. There is a macro which tells you
- how many clock ticks to a second.
-
- >Sorry for the neophyte question. Thanks for your help.
-
- This is system specific. In a real-time kernel (or any multi-tasking kernel,
- really) it is usually not acceptable to poll for a clock since you waste CPU
- time. There will be some system-specific timer facilities provided, such as:
-
- - the ability to put the process to sleep until an alarm goes off;
-
- - or set up an interrupt timer that will call a signal handler routine
- every so often. This may be good for what you want, since it gives
- an accurate time base (provided the interrupt timer is real time,
- rather than virtual process time).
-
- - ability to create timer objects, which you can reset/start/stop and
- read at any time.
-
- - ``callout routines''---you make a special request to the kernel to
- call a particular function with particular arguments at a particular
- time. The request is enqueued, and the function gets called later.
- Typical use: to turn off some signal (e.g. motor) after some delay
- without using an interrupt or extra thread.
-
- Find you what you can do under your system by consulting appropriate
- documentation, newsgroup, etc.
-
-
-
- >Chuck Marks
-
-
- --
-
-